package com.czh.controller;

import com.czh.domain.ResponseResult;
import com.czh.domain.dto.QueryTagDto;
import com.czh.domain.entity.Tag;
import com.czh.domain.vo.TagPageVo;
import com.czh.domain.vo.TagVo;
import com.czh.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 标签管理控制器
 */
@RestController
@RequestMapping("/content/tag")
public class TagManageController {
    @Autowired
    private TagService tagService;

    @GetMapping("/list")
    public ResponseResult<TagPageVo> list(Integer pageNum, Integer pageSize, QueryTagDto queryTagDto){
        return tagService.pageTagList(pageNum,pageSize, queryTagDto);
    }
    @PostMapping()
    public ResponseResult<Object> addTag(@RequestBody Tag tag){
        return tagService.addTag(tag);
    }
    @DeleteMapping("/{id}")
    public ResponseResult<Object> deleteTag(@PathVariable("id") Long id){
        return tagService.deleteTag(id);
    }
    @PutMapping()
    public ResponseResult<Object> updateTag(@RequestBody Tag tag){
        return tagService.updateTagById(tag);
    }
    //修改标签时填充信息
    @GetMapping("{id}")
    public ResponseResult<TagVo> getTagById(@PathVariable("id") Long id){
        return tagService.getTagById(id);
    }
    //写博客页面展示标签
    @GetMapping("/listAllTag")
    public ResponseResult<List<Tag>> listAllTag(){
        return tagService.listAllTag();
    }
}